package com.nju.edu.android_app;

import java.io.Serializable;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

import com.weibo.sdk.android.demo.R;

public class StreamAdapter extends ArrayAdapter<StreamItem> {
	private final LayoutInflater mInflater;

	public StreamAdapter(Context context) {
		super(context, 0);
		mInflater = LayoutInflater.from(getContext());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewGroup view = null;
		if (convertView == null) {
			view = (ViewGroup) mInflater.inflate(R.layout.item, parent,
					false);
		} else {
			view = (ViewGroup) convertView;
		}
		StreamItem item = getItem(position);
        if(item.image!=null)
        {
        	Bitmap bitmap=item.image;
        	((ImageView) view.findViewById(R.id.wei_pic)).setImageBitmap(bitmap);
        }
        else
        {
        	((ImageView) view.findViewById(R.id.wei_pic)).setVisibility(View.GONE);
		}
		//((ImageView) view.findViewById(R.id.head_photo)).setImageBitmap(item.mBitmap);
		((TextView) view.findViewById(R.id.name)).setText(item.mLine1);
		((TextView) view.findViewById(R.id.content)).setText(item.mLine2);
		((TextView) view.findViewById(R.id.wei_source)).setText("来自  "+Html.fromHtml(item.source));
		view.setTag(item.id);
		return view;
	}
}
